
function login() {
	var loginname = document.all.loginname.value;
	var password = document.all.password.value;
	var savepassword = document.all.savepassword.value;
	if (validate(loginname) === false) {
		Ext.MessageBox.show({title:"\u6d88\u606f", msg:"\u7528\u6237\u540d\u4e0d\u80fd\u4e3a\u7a7a", buttons:{"ok":"\u786e\u8ba4"}, width:200, icon:Ext.MessageBox.INFO, closable:true});
		return false;
	}
	if (validate(password) === false) {
		Ext.MessageBox.show({title:"\u6d88\u606f", msg:"\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a", buttons:{"ok":"\u786e\u8ba4"}, width:200, icon:Ext.MessageBox.INFO, closable:true});
		return false;
	}
	
	Ext.Ajax.request({
		url:"logon!handleLogin.action", 
		params:{loginname:loginname, password:password,savepassword:savepassword}, 
		success:function (resp) {
			var response = Ext.util.JSON.decode(resp.responseText);
			if(response.success != true){
				Ext.MessageBox.show({title:"\u6d88\u606f", msg:response.msg, buttons:{"ok":"\u786e\u8ba4"}, width:200, icon:Ext.MessageBox.WARNING, closable:true});
				return false;
			}
			window.location = "index!home.action";
		}, 
		failure:function () {
			Ext.MessageBox.show({title:"\u6d88\u606f", msg:"\u7cfb\u7edf\u4e0d\u80fd\u767b\u5f55\uff0c\u8bf7\u8054\u7cfb\u7ba1\u7406\u5458.", buttons:{"ok":"\u786e\u8ba4"}, width:200, icon:Ext.MessageBox.ERROR, closable:true});
		}
	});
}

var init = function () {

	Ext.get("login-panel").keys = [{key:[10, 13], fn:login}];
	Ext.get("login-panel").setStyle("display", "block");
	Ext.get("submitBtn").on({"click":{fn:login}});


};
Ext.onReady(init);


function validate(field) {
	if (field == "") {
		return false;
	}
	return true;
}